package Server;

import java.util.List;

import javax.swing.table.AbstractTableModel;

class MyTableModel extends AbstractTableModel {	
		String tableName;
		List<String> columnNames;
		List<Object[]> data ;
		List<String> typeData;
		List<Boolean> khoaChinh;
		public MyTableModel(List<Object[]> obj,List<String> names,List<String> types,String name,List<Boolean> khoa)
		{
			data = obj;
			columnNames = names;
			typeData = types;
			tableName = name;
			khoaChinh = khoa;
		}
		
		public List<Boolean> layDanhSachKhoaChinh()
		{
			return khoaChinh;
		}
		public int getColumnCount() {
			return columnNames.size();
		}

		public int getRowCount() {
			return data.size();
		}

		public String getColumnName(int col) {
			return columnNames.get(col);
		}
		public List<String> getColumnNames() {
			return columnNames;
		}
		public Object getValueAt(int row, int col) {
			return data.get(row)[col];
		}
		
		@Override
		public void setValueAt(Object value, int row, int col) {
			data.get(row)[col] = value;	
			fireTableCellUpdated(row, col);
			
		}
		
		public Class getColumnClass(int c) {
			return getValueAt(0, c).getClass();
		}
		
		public boolean isCellEditable(int row, int col) {
				return true;
		}
		
		public void delete()
		{
			data.remove(data.size()-1);
		}
		public void deleteRow(int row){
			data.remove(row);
		}
		public void addRow(Object[] newRow) {
			data.add(newRow);
		}
		public void addColumn(String name)
		{
			columnNames.add(name);			
		}
		public List<Object[]> getData() {
			return data;
		}

		public List<String> getTypeData() {
			return typeData;
		}
		public void setColumnNames(List<String> columnNames) {
			this.columnNames = columnNames;
		}
		public void setData(List<Object[]> data) {
			this.data = data;
		}
		public void setTypeData(List<String> typeData) {
			this.typeData = typeData;
		}
		public String getTableName() {
			return tableName;
		}
		public void setTableName(String tableName) {
			this.tableName = tableName;
		}
		public List<Boolean> getKhoaChinh() {
			return khoaChinh;
		}
		public void setKhoaChinh(List<Boolean> khoaChinh) {
			this.khoaChinh = khoaChinh;
		}
	}